package com.wdz.mvr.controllers;

import com.wdz.mvr.Services.ActorService;
import com.wdz.mvr.Services.ClassificationService;
import com.wdz.mvr.Services.CommentService;
import com.wdz.mvr.Services.MovieService;
import com.wdz.mvr.entities.Actor;
import com.wdz.mvr.entities.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.management.openmbean.CompositeData;
import java.util.List;

@Controller
@RequestMapping("comments")
public class CommentController {

    @Autowired
    CommentService commentService;

    @Autowired
    ActorService actorService;

    @Autowired
    MovieService movieService;

    @Autowired
    ClassificationService classificationService;




    @GetMapping
    public String displayComments(Model model){

        List<Comment> comments = commentService.getAll();
        model.addAttribute("Comments",comments);
        return "comments/list-comments";
    }

    @GetMapping("/new")
    public String displayCommentForm(Model model){

        Comment aComment = new Comment();
        model.addAttribute("comment",aComment);

        List<Actor> actors=actorService.getAll();
        model.addAttribute("allActors",actors);
        return "comments/new-comment";
    }

    @PostMapping("/save")
    public String creatComment(Model model, @RequestParam List<Long> actors, Comment comment){

        commentService.save(comment);

        return "redirect:/comments/new";

    }
}
